package opd

import (
	"API/client"
	"API/request"
	"API/response"
	"common/utils"
	"github.com/gin-gonic/gin"
	"opd_server/proto/opd"
)

func OutpatientRegistration(c *gin.Context) {
	var data request.OutpatientRegistrationRequest
	if err := c.ShouldBind(&data); err != nil {
		response.CurrencyErrResponse(c, 400, err.Error())
		return
	}
	userId := c.GetUint("userId")
	res, err := client.OutpatientRegistration(c, &opd.OutpatientRegistrationRequest{
		UserId:                int64(userId),
		DoctorId:              int64(data.DoctorId),
		AppointmentTimePeriod: int64(data.AppointmentTimePeriod),
		Remarks:               data.Remarks,
		AppointmentDate:       data.AppointmentDate,
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, utils.CutOutRpcError(err.Error()))
		return
	}
	response.CurrencySuccessResponse(c, "用户挂号成功", map[string]interface{}{"门诊号码": res})
}

func DoctorList(c *gin.Context) {
	res, err := client.DoctorList(c, &opd.DoctorListRequest{})
	if err != nil {
		response.CurrencyErrResponse(c, -1, utils.CutOutRpcError(err.Error()))
		return
	}
	response.CurrencySuccessResponse(c, "医生列表查看成功", map[string]interface{}{"医生信息": res})
}

func DoctorInfo(c *gin.Context) {
	var data request.DoctorInfo
	if err := c.ShouldBind(&data); err != nil {
		response.CurrencyErrResponse(c, 400, err.Error())
		return
	}
	res, err := client.DoctorInfo(c, &opd.DoctorInfoRequest{
		DoctorId: int64(data.DoctorId),
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, utils.CutOutRpcError(err.Error()))
		return
	}
	response.CurrencySuccessResponse(c, "医生详情查看成功", map[string]interface{}{"医生信息": res})
}

func AiConsultation(c *gin.Context) {
	var data request.AiConsultation
	if err := c.ShouldBind(&data); err != nil {
		response.CurrencyErrResponse(c, 400, err.Error())
		return
	}
	res, err := client.AiConsultation(c, &opd.AiConsultationRequest{
		Question: data.Question,
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, utils.CutOutRpcError(err.Error()))
		return
	}
	response.CurrencySuccessResponse(c, "以上内容由ai生成", map[string]interface{}{"生成内容": res})
}
